<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
<link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
<link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="scripts/authority/commonAll.js"></script>
<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
<script type="text/javascript" src="scripts/artDialog/artDialog.js?skin=default"></script>
<title>CDUESTC-后台系统</title>
<script type="text/javascript">
	/** 查询  **/
	var i = 1;
	var pages = ${tpages};
	var page = 0;
	function search(){
		/* if($("#stuAcademy").val()=='0'&&$("#entryDate").val()=='0'&&$("#teacherno").val()==''){
			location.href="stu_list.jsp"
		} */
		$.ajax({
			type:"post",//请求类型
			url:"/EDUSystem/teacher/getpage.do",//请求路径
			dataType:"json",//响应的数据类型
			data:$("#title").serialize(),
			success:function suc(dt){//响应成功后的回调函数
				var tb = dt.data
				if(dt.code==1){
					$("#total").html(dt.total);
					if(dt.pages!=0){
						$("#nowpagem").html(1 +" / "+ dt.pages);
					}else if(dt.pages==0){
						$("#nowpagem").html(0 +" / "+ dt.pages);
					}
					pages = dt.pages;
					//console.log("pages=="+pages)
					$("#tb").children().remove();
					//location.href="./stu_list.jsp";
					for (var i=0;i<tb.length;i++){
						$("#tb").append('<tr class="tv"><td><input type="checkbox" name="IDCheck" value="'+tb[i].teachId+'" class="acb"/></td><td>'+tb[i].teachId+'</td><td>'+tb[i].teachName+'</td><td>'+tb[i].teachGender+'</td><td>'+tb[i].positionNo+'</td><td>'+tb[i].salary+'</td><td>'+tb[i].entryData+'</td><td><a href="javascript:void(0);" onclick="edit('+tb[i].teachId+')" class="edit">编辑</a>&emsp;<a href="javascript:del(\''+tb[i].teachId+'\');">删除</a></td></tr>');
					}
				}else{
					alert(dt.message);
				}
			},
			errer:function err(){
				alert("服务器出现故障")
			}
		});
	}

	/** 新增   **/
	function addBtn(){
		var width=Math.round((window.screen.width)/4);
		var height=Math.round((window.screen.height)/6);
		window.open('teacher_add.html', 'newwindow', 'height=550, width=800, top='+height+',left='+width+',toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')

	}
	function edit(teachId){
		//alert(stuId)
		var width=Math.round((window.screen.width)/4);
		var height=Math.round((window.screen.height)/6);
		window.open('teacher_edit.html?teachId='+teachId, 'newwindow', 'height=550, width=800, top='+height+',left='+width+',toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')

		//window.open('stu_edit.html', 'newwindow', 'height=600, width=800, top=110, left=110, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')	
	}
	
	/** Excel导出  **/
	function exportExcel(){
		if(confirm('您确定要导出吗？')){
			location.href="/EDUSystem/teacher/outFile.do?teach="+$("#title").serialize();
		}
	}
	function delr(teachId){
		$.ajax({
			type:"post",//请求类型
			url:"/EDUSystem/teacher/delete.do?teachId=" + teachId,//请求路径
			dataType:"json",//响应的数据类型
			data:"",
			success:function suc(dt){//响应成功后的回调函数
				if(dt.code==1){
					location.href="./teacher_list.jsp";
				}else{
					alert(dt.message)
				}
			},
			errer:function err(){
				alert("服务器出现故障")
			}
		});
	}
	/** 删除 **/
	function del(stuId){
		// 非空判断
		if(stuId == '') return;
		if(confirm("您确定要删除吗？")){
			delr(stuId);
			alert("删除成功！");
		}
	}
	/** 批量删除 **/
	function batchDel(){
		if($("input[name='IDCheck']:checked").length<=0){
			art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'至少选择一条', ok:true,});
			return;
		}
		// 1）取出用户选中的checkbox放入字符串传给后台,form提交
		var allIDCheck = "";
		//var chk_value =[];//定义一个数组  
		if(confirm("您确定要删除吗？")){
			$("input[name='IDCheck']:checked").each(function(){
				delr($(this).val());
				//chk_value.push($(this).val());//将选中的值添加到数组chk_value中
	 			//alert($(this).val());
			});
			alert("删除成功！")
		}
	}

	
	/** 普通跳转 **/
	
	function jumpNormalPage(str){
		if(str=='up'){
			if(i!=1){
				page=i-1;
				i = i-1;
			}
			if(i==1){
				page=1;
			}
		}
		if(str=='low'){
			if(i!=pages){
				page=i+1;
				i = i + 1;
			}
			if(i==pages){
				page=pages
			}
		}if(str=='weiye'){
			page=pages
		}
		$.ajax({
			type:"post",//请求类型
			url:"/EDUSystem/teacher/getpage.do?nowpage=" + page,//请求路径
			dataType:"json",//响应的数据类型
			data:$("#title").serialize(),
			success:function suc(dt){//响应成功后的回调函数
				var tb = dt.data
				//console.log(tb)
				if(dt.code==1){
					if(dt.pages!=0){
						$("#nowpagem").html(page+" / "+ pages);
					}else if(dt.pages==0){
						$("#nowpagem").html(0 +" / "+ dt.pages);
					}
					
					$("#tb").children().remove();
					//location.href="./stu_list.jsp";
					for (var i=0;i<tb.length;i++){
						$("#tb").append('<tr class="tv"><td><input type="checkbox" name="IDCheck" value="'+tb[i].teachId+'" class="acb"/></td><td>'+tb[i].teachId+'</td><td>'+tb[i].teachName+'</td><td>'+tb[i].teachGender+'</td><td>'+tb[i].positionNo+'</td><td>'+tb[i].salary+'</td><td>'+tb[i].entryData+'</td><td><a href="javascript:void(0);" onclick="edit('+tb[i].teachId+')" class="edit">编辑</a>&emsp;<a href="javascript:del(\''+tb[i].teachId+'\');">删除</a></td></tr>');
					}
				}else{
					alert(dt.message)
				}
			},
			errer:function err(){
				alert("服务器出现故障")
			}
		});
	}
	function jumpNormalPage1(page){
		i=page;
		$.ajax({
			type:"post",//请求类型
			url:"/EDUSystem/teacher/getpage.do?nowpage=" + page,//请求路径
			dataType:"json",//响应的数据类型
			data:$("#title").serialize(),
			success:function suc(dt){//响应成功后的回调函数
				var tb = dt.data
				if(dt.code==1){
					if(dt.pages!=0){
						$("#nowpagem").html(page+" / "+ pages);
					}else if(dt.pages==0){
						$("#nowpagem").html(0 +" / "+ dt.pages);
					}
					$("#tb").children().remove();
					for (var i=0;i<tb.length;i++){
						$("#tb").append('<tr class="tv"><td><input type="checkbox" name="IDCheck" value="'+tb[i].teachId+'" class="acb"/></td><td>'+tb[i].teachId+'</td><td>'+tb[i].teachName+'</td><td>'+tb[i].teachGender+'</td><td>'+tb[i].positionNo+'</td><td>'+tb[i].salary+'</td><td>'+tb[i].entryData+'</td><td><a href="javascript:void(0);" onclick="edit('+tb[i].teachId+')" class="edit">编辑</a>&emsp;<a href="javascript:del(\''+tb[i].teachId+'\');">删除</a></td></tr>');
					}
				}else{
					alert(dt.message);
				}
			},
			errer:function err(){
				alert("服务器出现故障")
			}
		});
	}
	
	/** 输入页跳转 **/
	function jumpInputPage(){
		// 如果“跳转页数”不为空
		if($("#jumpNumTxt").val() != ''){
			var pageNum = parseInt($("#jumpNumTxt").val());
			// 如果跳转页数在不合理范围内，则置为1
			if(pageNum<1 | pageNum > pages){
				/* alert("输入页码不正确！") */
				art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'请输入合适的页数，\n自动为您跳到首页', ok:true,});
				pageNum = 1;
			}
			jumpNormalPage1(pageNum);
		}else{
			// “跳转页数”为空
			art.dialog({icon:'error', title:'友情提示', drag:false, resize:false, content:'请输入合适的页数，\n自动为您跳到首页', ok:true,});
			//alert("请输入页码！")
		}
	}
	function selectOrClearAllCheckbox() {
		//var checkStatus = $("#all").attr("checked");
		//console.log(checkStatus)
		if ($('#all').is(':checked')) {
			$("input[type='checkbox']").attr("checked", true);
		} else {
			$("input[type='checkbox']").attr("checked", false);
		}
	}
</script>
<style>
	.alt td{ background:black !important;}
</style>
</head>
<body>
	<form id="title" name="title">
		<input type="hidden" name="allIDCheck" value="" id="allIDCheck"/>
		<div id="container">
			<div class="ui_content">
				<div class="ui_text_indent">
					<div id="box_border">
						<div id="box_top">搜索</div>
						<div id="box_center">
							&emsp;入职日期
							<select name="entryData" id="entryDate" class="ui_select01" onchange="search();">
                                <option value="0">--请选择--</option>
                            </select>

							&emsp;教师工号&nbsp;&nbsp;<input type="text" id="teachId" name="teachId" class="ui_input_txt02" />
						</div>
						<div id="box_bottom">
							<input type="button" value="查询" class="ui_input_btn01" onclick="search();" /> 
							<input type="button" value="新增" class="ui_input_btn01"  onclick="addBtn();"/> 
							<input type="button" value="删除" class="ui_input_btn01" onclick="batchDel();" /> 
							<!-- <input type="button" value="导入" class="ui_input_btn01" id="importBtn" /> -->
							<input type="button" value="导出" class="ui_input_btn01" onclick="exportExcel();" />
						</div>
					</div>
				</div>
			</div>
			</div>
		</form>
		
		<form id="submitForm" name="submitForm">
		<div id="container">
			<div class="ui_content">
				<div class="ui_tb">
					<table class="table"  cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
						<tr>
							<th width="30"><input type="checkbox" id="all" onclick="selectOrClearAllCheckbox();" />
							</th>
							<th>教师工号</th>
							<th>姓名</th>
							<th>性别</th>
							<th>职务编号</th>
							<th>薪资待遇</th>
							<th>入职时间</th>
							<th>操作</th>
						</tr>
						<tbody id="tb">
						</tbody>
					</table>
				</div>
				<div class="ui_tb_h30">
					<div class="ui_flt" style="height: 30px; line-height: 30px;">
						共有
						<span class="ui_txt_bold04" id="total"></span>
						条记录，当前第
						<span class="ui_txt_bold04" id="nowpagem"></span>
						页
					</div>
					<div class="ui_frt">
						<!--    如果是第一页，则只显示下一页、尾页 -->
							
							<input type="button" value="首页" class="ui_input_btn01" onclick="jumpNormalPage1(1);"/>
							
							<input type="button" value="上一页" class="ui_input_btn01"
								onclick="jumpNormalPage('up');" />
								
								<input type="button" value="下一页" class="ui_input_btn01"
								onclick="jumpNormalPage('low');" />
							<input type="button" value="尾页" class="ui_input_btn01"
								onclick="jumpNormalPage('weiye');" />
						
						<!--     如果是最后一页，则只显示首页、上一页 -->
						
						转到第<input type="text" id="jumpNumTxt" class="ui_input_txt01" />页
							 <input type="button" class="ui_input_btn01" value="跳转" onclick="jumpInputPage();" />
					</div>
				</div>
			</div>
		</div>
	</form>
</body>
<script src="../js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$.ajax({
		type:"post",//请求类型
		url:"/EDUSystem/teacher/getpage.do",//请求路径
		dataType:"json",//响应的数据类型
		data:$("#title").serialize(),
		success:function suc(dt){//响应成功后的回调函数
			var tb = dt.data;
			$("#total").html(dt.total);
			$("#nowpagem").html(1+" / "+ dt.pages);
			for (var i=0;i<tb.length;i++){
				$("#tb").append('<tr class="tv"><td><input type="checkbox" name="IDCheck" value="'+tb[i].teachId+'" class="acb"/></td><td>'+tb[i].teachId+'</td><td>'+tb[i].teachName+'</td><td>'+tb[i].teachGender+'</td><td>'+tb[i].positionNo+'</td><td>'+tb[i].salary+'</td><td>'+tb[i].entryData+'</td><td><a href="javascript:void(0);" onclick="edit('+tb[i].teachId+')" class="edit">编辑</a>&emsp;<a href="javascript:del(\''+tb[i].teachId+'\');">删除</a></td></tr>');
			}
		},
		errer:function err(){
			alert("服务器出现故障")
		}
	});
	
	$.ajax({
		type:"post",//请求类型
		url:"/EDUSystem/teacher/getintime.do",//请求路径
		dataType:"json",//响应的数据类型
		data:"",
		success:function suc(dt){//响应成功后的回调函数
			var tb = dt.data;
			console.log(tb)
			for (var i=0;i<tb.length;i++){
				$("#entryDate").append('<option value="'+tb[i].entryData+'">'+tb[i].entryData+'</option>');
			}
		},
		errer:function err(){
			alert("服务器出现故障")
		}
	});
});
</script>
</html>
